/*
 * $Id: AboutBox.java,v 1.1 2003/05/15 10:22:27 znamenacek Exp $
 *
 * Copyright (c) Tomas Znamenacek
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 *
 */

package net.sf.vofce.gui;

import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Toolkit;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.util.ResourceBundle;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.ImageIcon;
import javax.swing.JPanel;
import javax.swing.JTabbedPane;
import javax.swing.border.EmptyBorder;

/**
 * Displays simple informational dialog.
 *
 * @author Tomas Znamenacek
 */
class AboutBox extends JDialog {

	/** Closing button. */
	private JButton ok;

	/** Localised resource strings. */
	private static ResourceBundle resources;

	/**
	 * Creates the dialog.
	 */
	public AboutBox(JFrame parent) {
	
		super(parent, resources.getString("about.title"), true);

		// Info tab
		JPanel infoPanel = new JPanel(new BorderLayout());
		JLabel image = new JLabel(getIcon("ski.gif"));
		image.setBorder(new EmptyBorder(10, 10, 10, 10));
		infoPanel.add(image, BorderLayout.CENTER);
		JPanel blurb = new JPanel(new FlowLayout());
		blurb.add(new JLabel(resources.getString("about.blurb")));
		infoPanel.add(blurb, BorderLayout.SOUTH);
	
		// Tabs
		JTextPanel authorPanel  = new JTextPanel(resources.getString("about.authors"));
		JTextPanel contactPanel = new JTextPanel(resources.getString("about.contacts"));
		JTextPanel licensePanel = new JTextPanel(resources.getString("about.license"));
		
		JTabbedPane tabs = new JTabbedPane();
		
		tabs.addTab(resources.getString("about.tabs.info"),    infoPanel);
		tabs.addTab(resources.getString("about.tabs.authors"), authorPanel);
		tabs.addTab(resources.getString("about.tabs.contact"), contactPanel);
		tabs.addTab(resources.getString("about.tabs.license"), licensePanel);
		
		tabs.setBorder(new EmptyBorder(10, 10, 10, 10));
		
		// Button bar
		JPanel buttonBar = new JPanel();
		buttonBar.setLayout(new FlowLayout());
		ok = new JButton(resources.getString("button.close"));
		ok.addActionListener(
				new ActionListener() {
					public void actionPerformed(ActionEvent a) {
						dispose();
					}
				});
		buttonBar.add(ok);

		// Dump it out
		Container canvas = getContentPane();
		canvas.setLayout(new BorderLayout());
		canvas.add(buttonBar, BorderLayout.SOUTH);
		canvas.add(tabs, BorderLayout.CENTER);
	
		// Adjust size
		pack();
		setSize(getPreferredSize());
		setResizable(false);
			
		// Center
		Dimension screenDim = Toolkit.getDefaultToolkit().getScreenSize();
		setLocation((int) ((screenDim.width - getWidth()) / 2), (int) ((screenDim.height - getHeight()) / 2));
	}

	/** Shows the dialog. */
	public void show() {

		getRootPane().setDefaultButton(ok);
		super.show();
	}
	
	/**
	 * Returns image associated with given resource id.
	 */
	private ImageIcon getIcon(String id) {

		return new ImageIcon(getClass().getResource("/" + id));
	}

	static {
		
		resources = ResourceBundle.getBundle("net.sf.vofce.gui.resources");
	}
}
